<!--
 * @Author: 毛鹏程 924171624@qq.com
 * @Date: 2024-09-12 10:17:35
 * @LastEditors: 毛鹏程 924171624@qq.com
 * @LastEditTime: 2024-09-12 10:50:40
 * @FilePath: \RuoYi-Vue3\src\autoComponents\Fm\FmButton\index.vue
 * @Description:组件为自动loading 使用组件需注意click绑定的方法必须是Promise 类型
-->

<template>
  <el-button :loading="loading" v-bind="attrs" @click="handleClick">
    <slot />
  </el-button>
</template>

<script setup>

// 防止事件穿透
defineOptions({
	inheritAttrs: false,
});

const props = defineProps(['onClick']);

const attrs = useAttrs();

console.log(attrs, props);

const loading = ref(false);

async function handleClick() {
	loading.value = true;
	try {
		await props.onClick();
	} catch (err) {
		console.log(err);
		return;
	} finally {
		loading.value = false;
	}
}

// 取消事件穿透
</script>
